﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;

public class Example1 : MonoBehaviour
{
    public Animator animator;
    public AnimationClip animationClip;
    public float speed = 1f;
    public float time = 0f;

    PlayableGraph mPlayableGraph;


    void OnEnable()
    {
        mPlayableGraph = new PlayableGraph();
        var playable = AnimationPlayableUtilities.PlayClip(animator, animationClip, out mPlayableGraph);

        //'AnimationPlayableUtilities.PlayClip' as same as below:
        //var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent<Animator>());
        //var clipPlayable = AnimationClipPlayable.Create(playableGraph, animationClip);
        //playableOutput.SetSourcePlayable(clipPlayable);
        //mPlayableGraph.Play();

        playable.SetSpeed(speed);
        playable.SetTime(time);

        GraphVisualizerClient.Show(mPlayableGraph, "Example1");
    }

    void OnDestroy()
    {
        mPlayableGraph.Destroy();
    }
}
